package top.wardyan.wbaseswt.conf.service.impl;

import top.wardyan.base.common.annotation.Service;
import top.wardyan.base.db.service.impl.BaseNonstandardServiceImpl;
import top.wardyan.wbaseswt.conf.model.SysID;
import top.wardyan.wbaseswt.conf.service.ISysIdService;

@Service
public class SysIdServiceImpl extends BaseNonstandardServiceImpl<SysID> implements ISysIdService{

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();

	private static final String SQL_FIND = "SELECT m.* FROM SYSID AS m WHERE (rCust_ID = 0 OR rCust_ID = ?) AND xTableName = ? AND xField = ?";
	
	
	@Override
	public String getTable() {
		return "SYSID";
	}



	@Override
	public Integer getId(Integer custID, String tableName, String field) {
		Integer rs = 0;
		SysID sid = this.find(custID, tableName, field);
		if(sid != null) {
			rs = sid.getXValue();
			if(rs == null) {
				rs = 0;
			}
			rs += 1;
			sid.setXValue(rs);
			this.update(sid);
		}
		return rs;
	}



	@Override
	public SysID find(Integer custID, String tableName, String field) {
		return this.findBySql(SQL_FIND, custID, tableName, field);
	}
	
	
}
